<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue3-escook</title>
  <link rel="stylesheet" href="./lib/style.css">
  <script type="importmap">
    {
      "imports" : {
        "vue": "./lib/vue-3.4.29.js"
      }
    }
  </script>
  <script type="module">
    import { createApp, ref, watch } from 'vue'

    const app = createApp({
      setup() {
        const user = ref({
          name: 'zs',
          address: {
            province: '河北省',
            city: '邯郸市'
          }
        })

        watch(() => user.value.name, (newName, oldName) => {
          console.log(newName, oldName)
        })

        watch(() => user.value.address.city, (newCity, oldCity) => {
          // 副作用函数
          console.log(newCity, oldCity)
        })

        return {
          user
        }
      }
    })

    app.mount('#app')
  </script>
</head>

<body>
  <div id="app">
    <span>姓名：</span>
    <input type="text" v-model="user.name">
    <hr>

    <span>城市：</span>
    <input type="text" v-model="user.address.city">
  </div>
</body>

</html>